package com.itstyle.seckill.topic.java8;

import com.google.common.collect.Lists;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Auther: liuwenxiang
 * @Date: 2020/4/4 13:59
 * @Description:
 */
@Data
@Builder
public class DefaultTestBean {

    private int id;
    private String name;
    private String area;


    public DefaultTestBean(int id, String name, String area) {
        this.id=id;
        this.name=name;
        this.area=area;
    }

    public static void main(String[] args) {

        List<DefaultTestBean> list =new ArrayList<>();
        list.add(new DefaultTestBean(1,"张三1","武汉1"));
        list.add(new DefaultTestBean(2,"张三2","武汉2"));
        list.add(new DefaultTestBean(3,"张三3","武汉3"));
        list.add(new DefaultTestBean(4,"张三4","武汉4"));
        list.add(new DefaultTestBean(5,"张三5","武汉5"));
        list.add(new DefaultTestBean(6,"张三6","武汉6"));
        list.add(new DefaultTestBean(7,"张三7","武汉7"));
        list.add(new DefaultTestBean(8,"张三8","武汉8"));
        //1
        Stream<String> stream = list.stream().map((e)->e.getName());
        //2
        Integer[] nums = new Integer[10];
        Stream<Integer> stream1 = Arrays.stream(nums);
        //3
        Stream<Integer> stream2 = Stream.of(1,2,3,4,5,6);


        Stream<Integer> stream3 = Stream.iterate(0, (x) -> x + 2).limit(10);


        list.stream().filter((e)->e.getId()>2).limit(3).forEach(System.out::println);


        List<Integer> list1 = Arrays.asList(1,2,3,4,5,6,7,8,9,10);

        Integer sum = list1.stream()
                .reduce(0, (x, y) -> x + y);

        System.out.println(sum);


        list.stream().map((e)->e.getName()).forEach(System.out::println);

        Function<String,String> function = (x)->{return  x+2;};

    }

}
